package com.tangding;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import hprose.common.HproseException;
import hprose.server.HproseTcpServer;
import hprose.util.concurrent.Promise;

public class TCPHelloServer {
	public static Promise hello(String name) throws HproseException {
		// context.clients.push("news", "this is a pushed message: " + name);
		return Promise.value("Hello " + name + "!");
	}

	public static Promise GetUsers(Map<String, Object> data) throws HproseException {
		List<Map<String, Object>> list = new ArrayList<>();
		Map<String, Object> user1 = new HashMap<>();
		user1.put("key", "123m1ljiqwf");
		user1.put("name", "游侠");
		user1.put("age", 15);
		list.add(user1);
		
		
		user1 = new HashMap<>();
		user1.put("key", "asdglaksdjmglik");
		user1.put("name", data);
		user1.put("age", 18);
		list.add(user1);
		
		return Promise.value(list);
	}
	
	public static Promise GetUser(Map<String, Object> data) throws HproseException {
		Map<String, Object> user1 = new HashMap<>();
		user1.put("key", "123m1ljiqwf");
		user1.put("name", "游侠");
		user1.put("age", 15);
		
		return Promise.value(user1);
	}

	public static String listUser() {
		return "游侠";
	}

	public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
		HproseTcpServer server = new HproseTcpServer("tcp://localhost:4321");
		server.setReactorThreads(2);

		server.add("hello", TCPHelloServer.class);
		server.add("GetUsers", TCPHelloServer.class);
		server.add("GetUser", TCPHelloServer.class);
		
		server.setDebugEnabled(true);
		server.publish("news");
		server.start();
		System.out.println("START");
		System.in.read();
		server.stop();
		System.out.println("STOP");
		// pool.shutdown();
	}
}